<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .layui-elem-quote {
        padding: 5px;
        margin-bottom: 15px;
        border-left: 5px solid var(--primary-color);
        font-weight: 600;
    }

    .delthumb {
        position: absolute;
        right: 0;
        z-index: 999;
        cursor: pointer;
        display: none;
    }

    .thumb_control {
        display: block;
    }

    .el-input__inner {
        height: 30px !important;
    }

    .layui-form .el-cascader {
        line-height: 30px;
        ;
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding ">
        <div class=" rc-pannel ">
            <div class=" rc-pannel-header rc-pagepadding rc-bold"> <i class="iconfont goback rc-pointer">&#xe62b;</i> 编辑栏目</div>
            <div class="rc-pannel-body rc-pagepadding">
                <form class="layui-form" action="" id="addform">

                    <div class="layui-tab layui-tab-brief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">基础信息</li>
                            <li>互动配置</li>
                            <li>SEO扩展信息</li>
                        </ul>

                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">


                                <div class="layui-form-item">
                                    <label class="layui-form-label">选择模型</label>
                                    <div class="layui-input-block">
                                        <select name="mid" autocomplete="off">
                                            <?php
                                            foreach ($models as $model) {
                                            ?>
                                                <option value="<?php echo $model['id'] ?>" <?php echo $cateinfo['mid'] == $model['id'] ? 'selected' : '' ?>><?php echo $model['title'] ?></option>
                                            <?php
                                            } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">父级栏目</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="pid" id="pid" autocomplete="off" value="<?php echo $cateinfo['pid'] ?>" lay-verify="required" class="layui-input" title="分类名称" />
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="title" id="title" value="<?php echo $cateinfo['title'] ?>" lay-verify="required" placeholder="请输入栏目名称 " autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目英文名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="entitle" id="entitle" value="<?php echo $cateinfo['entitle'] ?>" placeholder="请输入栏目英文名 " autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目图片</label>
                                    <div class="layui-input-block">
                                        <div class="layui-upload-drag" id="ID-upload-demo-drag" style="position: relative;">

                                            <a style="position: absolute;right:0 ;top:0;font-size:18px;color:#882424; <?php echo $cateinfo['pic'] ? '' : 'display:none' ?>" id="del_pic">
                                                <i class="iconfont">&#xe607;</i>
                                            </a>


                                            <i class="layui-icon layui-icon-upload nouploaded <?php echo $cateinfo['pic'] != '' ? 'layui-hide' : '' ?>"></i>
                                            <div class="nouploaded <?php echo $cateinfo['pic'] != '' ? 'layui-hide' : '' ?>">点击上传，或将文件拖拽到此处</div>
                                            <div id="ID-upload-demo-preview">
                                                <?php
                                                if ($cateinfo['pic']) {

                                                ?>
                                                    <img src="<?php echo $cateinfo['pic'] ?>" style="max-width:100px; max-height:100px" />
                                                    <input type="hidden" value="<?php echo $cateinfo['pic'] ?>" name="pic" />
                                                <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目模板</label>
                                    <div class="layui-input-block">
                                        <select name="catetemp">
                                            <?php
                                            foreach ($catetemps as $catetemp) {
                                            ?>
                                                <option value="<?php echo $catetemp ?>" <?php echo $catetemp == $cateinfo['catetemp'] ? 'selected' : '' ?>><?php echo $catetemp ?></option>
                                            <?php
                                            }
                                            ?>

                                        </select>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">内容页模板</label>
                                    <div class="layui-input-block">
                                        <select name="pagetemp">
                                            <?php
                                            foreach ($pagetemps as $pagetemp) {
                                            ?>
                                                <option value="<?php echo $pagetemp ?>" <?php echo $pagetemp == $cateinfo['pagetemp'] ? 'selected' : '' ?>><?php echo $pagetemp ?></option>
                                            <?php
                                            }
                                            ?>
                                        </select>
                                    </div>
                                </div>



                            </div>

                            <div class="layui-tab-item">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">允许评论</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="comment" title="是" value="1" <?php echo $cateinfo['comment'] == 1 ? 'checked' : '' ?>/>
                                        <input type="radio" name="comment" title="否" value="0" <?php echo $cateinfo['comment'] == 0 ? 'checked' : '' ?> />
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">允许点赞</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="praise" title="是" value="1" <?php echo $cateinfo['praise'] == 1 ? 'checked' : '' ?>/>
                                        <input type="radio" name="praise" title="否" value="0" <?php echo $cateinfo['praise'] == 0 ? 'checked' : '' ?> />
                                    </div>
                                </div>


                                <div class="layui-form-item">
                                    <label class="layui-form-label">允许收藏</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="collect" title="是" value="1" <?php echo $cateinfo['collect'] == 1 ? 'checked' : '' ?>/>
                                        <input type="radio" name="collect" title="否" value="0" <?php echo $cateinfo['collect'] == 0 ? 'checked' : '' ?> />
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">允许投稿</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="contribute" title="是" value="1" <?php echo $cateinfo['contribute'] == 1 ? 'checked' : '' ?>/>
                                        <input type="radio" name="contribute" title="否" value="0" <?php echo $cateinfo['contribute'] == 0 ? 'checked' : '' ?> />
                                    </div>
                                </div>



                            </div>

                            <div class="layui-tab-item">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">关键词</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="keyword" value="<?php echo $cateinfo['keyword'] ?>" placeholder="请输入关键词 " autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">描述</label>
                                    <div class="layui-input-block">
                                        <textarea class="layui-textarea" name="desc"><?php echo $cateinfo['desc'] ?></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目内容</label>
                                    <div class="layui-input-block">
                                        <?php
                                        echo element('ueditor', name: 'content', value: $cateinfo['content']);
                                        ?>
                                    </div>
                                </div>


                            </div>
                        </div>










                        <div class="layui-form-item rc-margin-bottom0">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">提交</button>
                                <button type="reset" class="layui-btn layui-btn-sm">重置</button>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>
    <script src="/static/admin/lib/layui/modules/cascader/cascader.js"></script>
    <link href="/static/admin/lib/layui/modules/cascader/cascader.css" rel="stylesheet">
    <script type='text/javascript'>
        layui.use(function() {

            var form = layui.form;
            var upload = layui.upload;

            var layCascader = layui.layCascader;
            var el_cascaderdata = '<?php echo $cates ?>';
            var el_cascaderdata_obj = eval("(" + el_cascaderdata + ")");

            var el_cascader_ = layCascader({
                elem: '#pid',
                value: <?php echo $cateinfo['pid'] ?>,
                filterable: true,
                options: el_cascaderdata_obj,
                clearable: true,
                props: {
                    value: 'id',
                    label: 'title',
                    checkStrictly: true,
                }
            });


            /**上传图片开始 */

            var defimg = '';

            //pic 上传
            upload.render({
                elem: '#ID-upload-demo-drag',
                url: '/app/cms/admin/Cate/edit?submit_type=uploadimg',
                done: function(res) {
                    $('.nouploaded').hide();
                    $('#ID-upload-demo-preview').html(`
                        <img src="` + res.data.path + `" style="max-width:100px; max-height:100px" />
                        <input type="hidden" value="` + res.data.path + `"  name="pic" />
                    `);

                    $('#del_pic').show();

                }
            });

            //删除pic
            $('#del_pic').click(function(event) {
                event.stopPropagation()
                $('.nouploaded').show();
                $(this).hide();
                $('#ID-upload-demo-preview').html('');
            });

            /**上传图片结束 */


            form.on('submit(submit)', function(data) {

                var postdata = data.field;
                delete postdata['file'];

                $.ajax({
                    url: '/app/cms/admin/Cate/edit?id=<?php echo request()->get('id') ?>', //请求路径
                    type: "POST", //请求方式
                    data: postdata, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {
                            toastr_success("编辑成功", function() {
                                window.location.href = '/app/cms/admin/Cate/index';
                            });
                        } else {
                            toastr_error(data.message);
                        }
                    },
                    error: function() {

                    },

                });
            });



        });
    </script>